package com.cy.pj.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class SysTimeAspect {
    @Pointcut("bean(moduleServiceImpl)")
    public void doTime(){}

    @Before("doTime()")
    public  void doBefore(){
        System.out.println("time doBefore()");
    }
    @After("doTime()")
    public void doAfter(){
        System.out.println("time doAfter()");
    }

    /**核心业务正常结束时执行* 说明：假如有after，先执行after,再执行returning*/
    @AfterReturning("doTime()")
    public  void doAfterReturning(){
        System.out.println("time doAfterReturning()");
    }

    /**核心业务出现异常时执行说明：假如有after，先执行after,再执行Throwing*/
    @AfterThrowing("doTime()")
    public  void doAfterThrowing(){
        System.out.println("time doAfterThrowing()");
    }

    @Around("doTime()")
    public Object doAround(ProceedingJoinPoint joinPoint)throws Throwable{
        System.out.println("doAround.before");
        try {
           Object obj = joinPoint.proceed();
            System.out.println("doAround.after");
            return obj;
        } catch (Throwable e) {
            System.out.println(e.getMessage());
            throw e;
        }

    }
}
